package com.yikes.yygh.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.yikes.yygh.common.utils.object.BeanUtils;
import com.yikes.yygh.controller.excel.DictExcel;
import com.yikes.yygh.mapper.DictMapper;
import com.yikes.yygh.pojo.entity.Dict;

/**
 * <p>
 *
 * </p>
 *
 * @Author: guanrong.yin
 * @Date: 2025/5/3 02:39
 */
public class DictListener extends AnalysisEventListener<DictExcel> {

    private DictMapper dictMapper;

    public DictListener(DictMapper baseMapper) {

        this.dictMapper = baseMapper;
    }

    /**
     * 一行一行读取
     * @param dictExcel
     * @param analysisContext
     */
    @Override
    public void invoke(DictExcel dictExcel, AnalysisContext analysisContext) {

        // 调用方法添加数据库
        Dict bean = BeanUtils.toBean(dictExcel, Dict.class);
        dictMapper.insert(bean);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
